﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for MyShopInfo
/// </summary>
public class MyShopInfo
{
    public List<ShopInfo> ListProduct { get; set; }

    public MyShopInfo()
    {
        ListProduct = new List<ShopInfo>();
    }

    public void Add(ShopInfo product)
    {
        if (!CheckExits(product.Id))
        {
            ListProduct.Add(product);
        }
        else
        {
            for (int i = 0; i < ListProduct.Count; i++)
            {
                if (ListProduct[i].Id == product.Id)
                {
                    ListProduct[i].Name = product.Name;
                    ListProduct[i].Address = product.Address;
                    ListProduct[i].Phone = product.Phone;
                    ListProduct[i].Name = product.Notes;
                    break;
                }
            }
        }
    }


    public void UpdateQuantity(string name, string address, string phone, string notes)
    {
        ShopInfo item = ListProduct.Where(p => p.Id == 1).FirstOrDefault();
        if (item != null)
        {
            item.Id = 1;
            item.Name = name;
            item.Address = address;
            item.Phone = phone;
            item.Notes = notes;
        }
        else
        {
            item.Id = 1;
            item.Name = name;
            item.Address = address;
            item.Phone = phone;
            item.Notes = notes;
        }
    }

    private bool CheckExits(int id)
    {
        foreach (ShopInfo product in ListProduct)
        {
            if (product.Id == id)
                return true;
        }
        return false;
    }
}